package com.zj.ssm.service.impl;

import com.zj.ssm.mapper.NewsOpinionMapper;
import com.zj.ssm.pojo.domain.Opinion;
import com.zj.ssm.pojo.domain.query.NewsOpinionsQuery;
import com.zj.ssm.pojo.domain.vo.OpinionVO;
import com.zj.ssm.result.AjaxResult;
import com.zj.ssm.service.NewsOpinionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @author wxr
 * @version 1.0
 * @date 2022/2/14 21:17
 */
@Service
public class NewsOpinionServiceImpl implements NewsOpinionService {
    @Autowired
    private NewsOpinionMapper newsOpinionMapper;
    @Override
    public AjaxResult opinions(NewsOpinionsQuery newsOpinions) {
        List<Opinion> news = newsOpinionMapper.queryNewsOpinions(newsOpinions);
        Long aLong = newsOpinionMapper.queryNewsTotalOpinions(newsOpinions);
        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("currentData",news);
        objectObjectHashMap.put("totalCount",aLong);
        return AjaxResult.success(objectObjectHashMap);
    }

    @Override
    public AjaxResult deleteNewsOpinion(Integer id) {
        int i = newsOpinionMapper.deleteNewsOpinion(id);
        if (i<0){
            return AjaxResult.fail();
        }
        return AjaxResult.success();
    }

    @Override
    public AjaxResult send(OpinionVO opinionVO) {
        int i = newsOpinionMapper.send(opinionVO);
        if (i<0){
            return AjaxResult.fail();
        }
        return AjaxResult.success();
    }
}
